<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*
      语义化，定义我们语义化错误
      1. 继承Error
      2. 重写name属性，设为类名（字符串）
      */

      class AgeRangeError extends Error {
        name = "AgeRangeError";
      }
      class PhoneError extends Error {
        name = "PhoneError";
      }

      try {
        // throw new AgeRangeError("年龄范围错误");
        throw new PhoneError("手机格式错误");
      } catch (error) {
        console.log(error);
      }

      // throw new Error("手机格式错误");
      // throw new Error("年龄范围错误");

      // JSON.parse({ "": "" });
    </script>
  </body>
</html>
